package com.yjha.lzmarathonsys.value;

import com.yjha.lzmarathonsys.enmu.ErrorTypeEnum;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author my
 * 返回类
 */
@Data
public class Rest {

    /**
     * 返回响应码
     */
    private short code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 携带数据
     */
    private Map<String, Object> data = new HashMap<>();

    private Rest() {}

    private Rest(short code) {
        this.code = code;
    }

    private Rest(short code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Rest(short code, String msg, Map<String, Object> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Rest ok() {
        return new  Rest(ErrorTypeEnum.SUCCESS);
    }

    public static Rest ok(String msg) {
        return new  Rest(ErrorTypeEnum.SUCCESS, msg);
    }

    public static Rest ok(String msg, Map<String, Object> data) {
        return new  Rest(ErrorTypeEnum.SUCCESS, msg, data);
    }

    public static Rest err() {
        return new Rest(ErrorTypeEnum.ERROR_500);
    }

    public static Rest err(short code) {
        return new Rest(code);
    }

    public static Rest err(String msg) {
        return new Rest(ErrorTypeEnum.ERROR_400, msg);
    }

    public static Rest err(short code, String msg) {
        return new Rest(code, msg);
    }

    public static Rest err(short code, String msg, Map<String, Object> data) {
        return new Rest(code, msg, data);
    }

    public Rest setData(String k, Object v) {
        this.data.put(k, v);
        return this;
    }

}